package jetbrains.lb.refik;


import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Set;



/**
 * @author Leonid Bushuev
 */
public class RefikProjectComponent extends AbstractProjectComponent
    implements ProjectComponent
{
    final Project project;

    private Set<XmlFile> involvedXmlFiles = Collections.emptySet();


    public RefikProjectComponent(Project project)
    {
        super(project);
        this.project = project;
    }

    @NotNull
    public String getComponentName()
    {
        return "Refik App";
    }

    public void initComponent()
    {
        // do nothing
    }

    public void disposeComponent()
    {
        // do nothing
    }

    @Override
    public void projectOpened()
    {
        // Messages.showMessageDialog("Hello, people!", "Refik App", Messages.getInformationIcon());
        involvedXmlFiles =
                RefikFilesLister.retrieveAllInvolvedFiles(project);
    }

    @Override
    public void projectClosed()
    {
        // Messages.showMessageDialog("Good Bye!", "Refik App", Messages.getInformationIcon());
        involvedXmlFiles = Collections.emptySet();
    }


    boolean isFileInvolved(PsiFile file)
    {
        return involvedXmlFiles.contains(file);
    }

}
